<template>
	<view>
		<view class="picker-modal" v-if="show"></view>
		<view class="picker-content" :style="{transform:  show ? 'translateY(0)' : 'translateY(100%)'}">
			<view class="picker-header">
				<view @click="onClose">取消</view>
				 <view class="packer-title">{{ title }}</view>
				<view @click="onConfirm">确定</view>
			</view>
			<scroll-view scroll-y="true" style="height: 50vh;">
				<view class="uni-list">
					<view class="level-list">
						<view class="level-item" v-for="(item,index) in data" :key="item.id"
							:class="{active:activeLevel == index}" @click="activeLevel = index">
							<image class="icon-style" v-show="activeLevel != index"
								src="/static/images/work/dbd//selected_no.png" mode="aspectFill"></image>
							<image class="icon-style" v-show="activeLevel == index"
								src="/static/images/work/dbd//selected_yes.png" mode="aspectFill"></image>
							<text class="content">{{item.name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default{
		name: "ManagerLevelPicker",
		props:{
			//标题文字
			title: {
				type: String,
				default: ""
			},
			// 数据
			data: {
        type: Array
			}
		}, 
		data(){
			return{
				show: false,
				value: [0],
				current: undefined,
				activeLevel: undefined,
			}
		},
		methods:{
			// 打开
			open(title,type){
				this.show = true
			},
			//确定
			onConfirm(){
				this.show = false
				const selectData =  {
					value: this.data[this.activeLevel].id,
					name: this.data[this.activeLevel].name
				}
				this.$emit('confirm', selectData) 
			},
			// 取消
			onClose(){
				this.show = false
			},
			//滑动picker
			onChange(e) {
				this.value = e.detail.value
			},
			radioChange(e) {
				console.log(e);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.picker-modal{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.4);
	}
	.picker-content{
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 99;
		background-color: #fff;
		transition: all .3s;
	}
	.picker-header{
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin:0 20rpx;
		padding: 20rpx 0;
	}
	.packer-title{
		text-align: center;
	}
	.picker-view {
		position: relative;
		bottom: 0;
		left: 0;
		right: 0;
		height: 490rpx;
		background-color: rgba(255, 255, 255, 1);
	}
	.picker-item {
		text-align: center;
		line-height: 70rpx;
		text-overflow: ellipsis;
	}
	
	.level-list {
		
		.level-item {
			display: flex;
			align-items: center;
			margin-left: 20rpx;
			color: #333;
			line-height: 42rpx;
			padding: 20rpx;
			.icon-style {
				width: 36rpx;
				height: 36rpx;
				margin-right: 10rpx;
			}
			
			.content {
				flex: 1;
			}
		}
	}
</style>
